
// --- 隐藏所有
function HideAll() {
	var items = document.getElementsByClassName("optiton");
	for (var j=0; j<items.length; j++) {
		items[j].style.display = "none";
	}
}
// --- 设置cookie
function setCookie(sName,sValue,expireHours) {
	var cookieString = sName + "=" + escape(sValue);
	//;判断是否设置过期时间
	if (expireHours>0) {
		 var date = new Date();
		 date.setTime(date.getTime + expireHours * 3600 * 1000);
		 cookieString = cookieString + "; expire=" + date.toGMTString();
	}
	document.cookie = cookieString;
}
//--- 获取cookie
function getCookie(sName) {
  var aCookie = document.cookie.split("; ");
  for (var j=0; j < aCookie.length; j++){
	var aCrumb = aCookie[j].split("=");
	if (escape(sName) == aCrumb[0])
	  return unescape(aCrumb[1]);
  }
  return null;
}

// --- 获取ClassName
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var j = 0; j < elem.length; j++) {
		var classes = elem[j].className;
		if (myclass.test(classes)) retnode.push(elem[j]);
	}
	return retnode;
}

window.onload = function() {	
	var show_item = "opt_1";
	if (getCookie("show_item") != null) {
		 show_item= "opt_" + getCookie("show_item");
	} 
	var obj = document.getElementById(show_item);
	if (obj != null)
		obj.style.display = "block";
	 
	var links = document.getElementsByTagName('a');
	for(var k = 0; k < links.length; k++)
	{
		if (links[k].id != '')
		{
			links[k].onclick = function() {
					setCookie('selected_item', this.id);
			}
		}
	}
	
	var selected_item = getCookie('selected_item');
	if (selected_item != null) {
		 var obj = document.getElementById(selected_item);
		 if (obj != null)
		 	obj.className = 'itemselected';
	} 
}

function onclickmenu(obj)
{
	var o = document.getElementById("opt_" + obj.name);
	if (o.style.display != "block") {
		HideAll();
		o.style.display = "block";
		setCookie("show_item", obj.name);
	}
	else {
		o.style.display = "none";
	}
}


function checknumber()
{
	var a = document.getElementsByTagName("input");
   for (var i=0; i<a.length; i++)
   {   
		if(a[i].type == 'text' && a[i].alt == 'numeric')
		{
			 if(isNaN(a[i].value))
			 {
				  a[i].focus();
				  alert("数据格式不正确，必须是数字！"); 
				  return false;
			 } //if(isNaN(form1.elements[i].value)
		}     //if(form1.elements[i].type="text")                        
    }   
}